package com.example.service.impl;


import com.example.mapper.DiscipleMapper;
import com.example.pojo.Disciple;
import com.example.pojo.PageBean;
import com.example.service.DiscipleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class DiscipleServicelmpl implements DiscipleService {
    @Autowired
    private DiscipleMapper discipleMapper;

    @Override
    public void delete(List<Integer> ids) {
        discipleMapper.delete(ids);
    }

    @Override
    public PageBean page(String name, Short gender, LocalDate begin, LocalDate end, Integer page, Integer pageSize,Boolean ise) {
        //设置分页参数
        PageHelper.startPage(page,pageSize);
        List<Disciple> list = discipleMapper.list(name, gender, begin, end,ise);
        Page<Disciple> p= (Page<Disciple>) list;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    @Override
    public PageBean page2(String name, Short job, Short deptId,LocalDate begin, LocalDate end, Integer page, Integer pageSize, Boolean ise) {
        //设置分页参数
        PageHelper.startPage(page,pageSize);
        List<Disciple> list = discipleMapper.list2(name, job, deptId,begin, end,ise);
        Page<Disciple> p= (Page<Disciple>) list;
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }


    @Override
    public List<Disciple> jobList() {
        return discipleMapper.getJoblist();
    }

    @Override
    public void save(Disciple disciple) {
        disciple.setCreateTime(LocalDateTime.now());
        disciple.setUpdateTime(LocalDateTime.now());
        discipleMapper.insert(disciple);
    }

    @Override
    public Disciple getById(Integer id) {
        return discipleMapper.getById(id);
    }

    @Override
    public Disciple login(Disciple disciple) {
        return discipleMapper.login(disciple);
    }

    @Override
    public void update(Disciple disciple) {
        disciple.setUpdateTime(LocalDateTime.now());
        discipleMapper.update(disciple);
    }


}
